package com.newviews.tcmip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newviews.tcmip.common.constant.CommonConsts;
import com.newviews.tcmip.common.model.PageModel;
import com.newviews.tcmip.common.model.ResultModel;
import com.newviews.tcmip.dao.EtcmHerbExMapper;
import com.newviews.tcmip.dao.EtcmPxExMapper;
import com.newviews.tcmip.pojo.po.*;
import com.newviews.tcmip.dao.EtcmIngrExMapper;
import com.newviews.tcmip.pojo.vo.EtcmCommonBaseInfoRespVO;
import com.newviews.tcmip.service.inf.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmIngrByHerbExportReqVO;
import com.newviews.tcmip.web.vo.etcmherb.download.EtcmIngrDetailsExportReqVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 组成成分扩展信息 服务实现类
 * </p>
 *
 * @author lxc
 * @since 2024-03-01
 */
@Service
public class EtcmIngrExServiceImpl extends ServiceImpl<EtcmIngrExMapper, EtcmIngrExPo> implements EtcmIngrExServiceInf {
    @Resource
    private EtcmIngrServiceInf etcmIngrServiceInf;
    @Resource
    private EtcmIngrExMapper etcmIngrExMapper;
    @Resource
    private EtcmHerbExMapper etcmHerbExMapper;
    @Resource
    private EtcmPxExServiceInf etcmPxExServiceInf;
    @Resource
    private EtcmDiseaseExServiceInf etcmDiseaseExServiceInf;

    @Resource
    private EtcmExperimentalRecordsExServiceInf etcmExperimentalRecordsExServiceInf;
    @Resource
    private EtcmPxExMapper etcmPxExMapper;


    @Override
    public List<Map<String, String>> downloadIngredientInformation(EtcmIngrDetailsExportReqVO reqVO) {
        List<EtcmIngrExPo> list = etcmIngrExMapper.getList(new QueryWrapper<EtcmIngrExPo>()
                .eq("t1.status", CommonConsts.COMMON_YES)
                .eq("t2.status", CommonConsts.COMMON_YES)
                .eq("t1.ingr_id", reqVO.getIngrId())
                .eq("t2.language_code", reqVO.getLangCode())
                .eq("t2.ui_type_code", reqVO.getUiTypeCode())
                .isNotNull("t1.ingr_ex_con")
                .orderByAsc("t2.ui_el_sort")
        );
        List<Map<String,String>> resList = new ArrayList<>();
        HashMap<String,String> map = new LinkedHashMap<>(16);
        for (EtcmIngrExPo etcmIngrExPo : list) {
            map.put(etcmIngrExPo.getUiElName(), etcmIngrExPo.getIngrExCon());
        }
        resList.add(map);
        return resList;
    }

    @Override
    public List<Map<String, String>> downloadExperimentalRecords(EtcmIngrDetailsExportReqVO reqVO) {
//        List<EtcmExperimentalRecordsHerbPo> list = etcmExperimentalRecordsHerbServiceInf.list(new QueryWrapper<EtcmExperimentalRecordsHerbPo>()
//                .eq("ingr_id", reqVO.getIngrId())
//                .eq("status", CommonConsts.COMMON_YES)
//        );
//        List<String> herbIdList = list.stream().map(EtcmExperimentalRecordsHerbPo::getHerbId).distinct().collect(Collectors.toList());
//        QueryWrapper<EtcmExperimentalRecordsPo> wrapper = new QueryWrapper<>();
//        wrapper.in("t1.herb_id", herbIdList);
//        wrapper.eq("t1.status",CommonConsts.COMMON_YES);
//        wrapper.eq("t2.status",CommonConsts.COMMON_YES);
//        if (StringUtils.isNotBlank(reqVO.getContent())){
//            wrapper.and(w->w.like("t2."+ EtcmExperimentalRecordsPo.ER_ZH_NAME, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_ZH_NAME_ABB, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_EN_NAME, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_EN_NAME_ABB, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_LATIN_NAME, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_LATIN_NAME_ABB, reqVO.getContent())
//                    .or().like("t2."+EtcmExperimentalRecordsPo.ER_NAME_ALIAS, reqVO.getContent()));
//        }
//        List<EtcmExperimentalRecordsPo> erList = etcmHerbExMapper.getListByExperimentalRecords(wrapper);
//
//        List<Map<String, String>> resList = new ArrayList<>();
//        for (EtcmExperimentalRecordsPo record : erList) {
//            HashMap<String, String> map = new HashMap<>();
//            List<EtcmExperimentalRecordsExPo> exList = etcmExperimentalRecordsExServiceInf.list(new QueryWrapper<EtcmExperimentalRecordsExPo>()
//                    .eq(EtcmExperimentalRecordsExPo.STATUS, CommonConsts.COMMON_YES)
//                    .eq(EtcmExperimentalRecordsExPo.ER_ID, record.getId())
//                    .eq("language_code", reqVO.getLangCode())
//                    .eq("ui_type_code", reqVO.getUiTypeCode())
//            );
//            for (EtcmExperimentalRecordsExPo etcmExperimentalRecordsExPo : exList) {
//                map.put(etcmExperimentalRecordsExPo.getUiElCode(), etcmExperimentalRecordsExPo.getErExCon());
//            }
//            resList.add(map);
//        }
//        return resList;
        return null;
    }





    @Override
    public List<Map<String, String>> getTargetDownload(String type, String content, String langCode, String uiTypeCode, String ingrId, String sortType) {
        if (StringUtils.isBlank(type)){
            return new ArrayList<>();
        }
        QueryWrapper<EtcmIngrPo> wrapper = new QueryWrapper<>();
        wrapper.in("t2.target_type_code",type.split(","));
        if (StringUtils.isNotBlank(content)) {
            wrapper.and(w->w.like("t2.target_zh_name", content)
                    .or().like("t2.target_zh_name_py", content)
                    .or().like("t2.target_zh_name_wb", content)
                    .or().like("t2.target_zh_name_abb", content)
                    .or().like("t2.target_en_name", content)
                    .or().like("t2.target_en_name_abb", content)
                    .or().like("t2.target_latin_name", content)
                    .or().like("t2.target_latin_name_abb", content)
                    .or().like("t2.target_name_alias", content));
        }

        wrapper.eq("t1.status", CommonConsts.COMMON_YES);
        wrapper.eq("t1.ingr_id", ingrId);
        wrapper.eq("t3.language_code", langCode);

//        wrapper.groupBy("t1.id");
        if (sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)) {
            wrapper.orderByAsc("t1.target_id");
        } else {
            wrapper.orderByDesc("t1.target_id");
        }

        List<EtcmIngrTargetPo> pageTarget = etcmIngrExMapper.getTargetDownload(wrapper);

        List<Map<String, String>> resList = new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        pageTarget.forEach(etcmIngrTargetPo -> {
            Map<String, String> map = getStringStringMap(langCode, etcmIngrTargetPo, uiElName);
            resList.add(map);
        });
        return resList;
    }

    @Override
    public List<Map<String, String>> downloadSynergisticIngredients(String ingrId, String sortType, String content, String langCode, String uiTypeCode) {
        QueryWrapper<EtcmIngrIngrPo> wrapper=new QueryWrapper<>();
        if(com.newviews.tcmip.common.utils.StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("t1.ingr_zh_name",content)
                    .or().like("t1.ingr_zh_name_abb", content)
                    .or().like("t1.ingr_zh_name_wb", content)
                    .or().like("t1.ingr_zh_name_py",content)
                    .or().like("t1.ingr_en_name", content)
                    .or().like("t1.ingr_en_name_abb", content)
                    .or().like("t1.ingr_latin_name", content)
                    .or().like("t1.ingr_latin_name_abb", content)
                    .or().like("t1.ingr_name_alias", content)

                    .or().like("t3.ingr_zh_name",content)
                    .or().like("t3.ingr_zh_name_abb", content)
                    .or().like("t3.ingr_zh_name_wb", content)
                    .or().like("t3.ingr_zh_name_py",content)
                    .or().like("t3.ingr_en_name", content)
                    .or().like("t3.ingr_en_name_abb", content)
                    .or().like("t3.ingr_latin_name", content)
                    .or().like("t3.ingr_latin_name_abb", content)
                    .or().like("t3.ingr_name_alias", content)
            );
        }
        wrapper.eq("t1.ingr_code", ingrId);
        //wrapper.orderByAsc("t2.ingr_ingr_distance");
        wrapper.isNotNull("t2.ingr_ingr_distance");
        wrapper.gt("t2.ingr_ingr_distance",0);
        wrapper.last("limit 200");


        List<EtcmIngrIngrPo> iPage=etcmIngrExMapper.getPageBySynergisticIngredients( wrapper);
        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        List<Map<String,String>> resultList=new ArrayList<>();

        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            iPage = iPage.stream().sorted(Comparator.comparing(EtcmIngrIngrPo::getIngrIngrDistance)).collect(Collectors.toList());
        }else {
            iPage = iPage.stream().sorted(Comparator.comparing(EtcmIngrIngrPo::getIngrIngrDistance).reversed()).collect(Collectors.toList());
        }

        iPage.forEach(etcmIngrIngrPo -> {
            Map<String, String> map = getStringStringMap(langCode, etcmIngrIngrPo, uiElName);
            resultList.add(map);
        });
        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadAssociatedDiseases(String ingrId, String sortType, String content, String langCode, String uiTypeCode) {
        QueryWrapper<EtcmIngrDiseasePo> wrapper=new QueryWrapper<>();
        if(com.newviews.tcmip.common.utils.StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("A.ingr_zh_name",content)
                    .or().like("A.ingr_zh_name_abb", content)
                    .or().like("A.ingr_zh_name_wb", content)
                    .or().like("A.ingr_zh_name_py",content)
                    .or().like("A.ingr_en_name", content)
                    .or().like("A.ingr_en_name_abb", content)
                    .or().like("A.ingr_latin_name", content)
                    .or().like("A.ingr_latin_name_abb", content)
                    .or().like("A.ingr_name_alias", content)

                    .or().like("B.disease_zh_name",content)
                    .or().like("B.disease_zh_name_abb", content)
                    .or().like("B.disease_zh_name_wb", content)
                    .or().like("B.disease_zh_name_py",content)
                    .or().like("B.disease_en_name", content)
                    .or().like("B.disease_en_name_abb", content)
                    .or().like("B.disease_latin_name", content)
                    .or().like("B.disease_latin_name_abb", content)
                    .or().like("B.disease_name_alias", content)
            );
        }
        wrapper.eq("C.ingr_id", ingrId);
        wrapper.orderByAsc("C.ingr_disease_distance");
        wrapper.isNotNull("C.ingr_disease_distance");
        wrapper.gt("C.ingr_disease_distance",0);
        wrapper.last("limit 200");


        List<EtcmIngrDiseasePo> iPage=etcmIngrExMapper.getPageByAssociatedDiseases( wrapper);

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        List<Map<String,String>> resultList=new ArrayList<>();
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            iPage = iPage.stream().sorted(Comparator.comparing(EtcmIngrDiseasePo::getIngrDiseaseDistance)).collect(Collectors.toList());
        }else {
            iPage = iPage.stream().sorted(Comparator.comparing(EtcmIngrDiseasePo::getIngrDiseaseDistance).reversed()).collect(Collectors.toList());
        }

        iPage.forEach(etcmIngrDiseasePo -> {
            Map<String, String> map = getStringStringMap(langCode, etcmIngrDiseasePo, uiElName);
            resultList.add(map);
        });

        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadPx(String ingrId, String sortType, String content, String langCode, String uiTypeCode) {
        QueryWrapper<EtcmPxPo> wrapper = new QueryWrapper<>();
        wrapper.eq("t1.ingr_id", ingrId);

        if (StringUtils.isNotBlank(content)){
            wrapper.and(w -> w.like("t3.px_zh_name",content)
                    .or().like("t3.px_zh_name_abb", content)
                    .or().like("t3.px_zh_name_wb", content)
                    .or().like("t3.px_zh_name_py",content)
                    .or().like("t3.px_en_name", content)
                    .or().like("t3.px_en_name_abb", content)
                    .or().like("t3.px_latin_name", content)
                    .or().like("t3.px_latin_name_abb", content)
                    .or().like("t3.px_name_alias", content)

            );
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t3.px_code");
        }else {
            wrapper.orderByDesc("t3.px_code");
        }
        List<EtcmPxExPo> page = etcmIngrExMapper.downloadPx(wrapper,uiTypeCode,langCode);


        Map<String,List<EtcmPxExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmPxExPo record : page) {
            List<EtcmPxExPo> disList = new ArrayList<>();
            String[] uielcodeList = record.getUiElCode().split("\\|\\|");
            String[] pxExconList = record.getPxExCon().split("\\|\\|");



            for (int i = 0; i < uielcodeList.length; i++) {
                EtcmPxExPo etcmPxExPo = new EtcmPxExPo();
                for (int j = 0; j < pxExconList.length; j++) {
                    etcmPxExPo.setUiElCode(uielcodeList[i]);
                    if (i == j){
                        etcmPxExPo.setPxExCon(pxExconList[j]);
                    }
                }
                disList.add(etcmPxExPo);
            }

            disMap.put(record.getPxCode(), disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmPxExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmPxExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmPxExPo etcmPxExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmPxExPo.getUiElCode())){
                            mapRes.put(etcmPxExPo.getUiElCode(), etcmPxExPo.getPxExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }
        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadHerb(String ingrId, String sortType, String content, String langCode, String uiTypeCode, String herbFlavorCode, String herbPropertyCode, String herbMeridiansCode) {
        QueryWrapper<EtcmHerbExPo> wrapper = new QueryWrapper<>();

        if (StringUtils.isBlank(herbFlavorCode) && StringUtils.isBlank(herbPropertyCode) && StringUtils.isBlank(herbMeridiansCode)){
            return new ArrayList<>();
        }

        if (StringUtils.isNotBlank(herbFlavorCode)){
            wrapper.in("t2.flavor_code",herbFlavorCode.split(","));
        }

        if (StringUtils.isNotBlank(herbPropertyCode)){
            wrapper.in("t3.property_code",herbPropertyCode.split(","));
        }

        if (StringUtils.isNotBlank(herbMeridiansCode)){
            wrapper.in("t4.meridians_code",herbMeridiansCode.split(","));
        }
        if (StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "t1.herb_zh_name", content)
                    .or().like( "t1.herb_zh_name_py", content)
                    .or().like( "t1.herb_zh_name_wb",content)
                    .or().like( "t1.herb_zh_name_abb", content)
                    .or().like( "t1.herb_en_name", content)
                    .or().like( "t1.herb_en_name_abb", content)
                    .or().like( "t1.herb_latin_name", content)
                    .or().like( "t1.herb_latin_name_abb", content)
                    .or().like( "t1.herb_name_alias", content)
            );
        }

        wrapper.eq("t1.status", CommonConsts.COMMON_YES);
        wrapper.eq("s2.ingr_id", ingrId);
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("s1.herb_id");
        }else {
            wrapper.orderByDesc("s1.herb_id");
        }
        wrapper.groupBy("s1.herb_id,s1.ui_el_code, s1.herb_ex_con");
        List<EtcmHerbExPo> page = etcmIngrExMapper.getHerbDownload(wrapper,uiTypeCode, langCode);


        // List<Map<String,String>> resList = new ArrayList<>();
        Map<String,List<EtcmHerbExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmHerbExPo record : page) {
            List<EtcmHerbExPo> disList = new ArrayList<>();

            String[] uiElCodeList = record.getUiElCode().split("\\|\\|");
            String[] herbExConList = record.getHerbExCon().split("\\|\\|");
            for (int i = 0; i < uiElCodeList.length; i++) {
                EtcmHerbExPo etcmHerbExPo = new EtcmHerbExPo();

                for (int j = 0; j < herbExConList.length; j++) {
                    if (i == j){
                        etcmHerbExPo.setUiElCode(uiElCodeList[i]);
                        etcmHerbExPo.setHerbExCon(herbExConList[j]);

                    }
                }
                disList.add(etcmHerbExPo);
            }

            disMap.put(record.getHerbId(),disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        etcmUiElPos = etcmUiElPos.stream().filter(etcmUiElPo -> etcmUiElPo.getUiElSort() != 3).collect(Collectors.toList());
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmHerbExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmHerbExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmHerbExPo etcmHerbExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmHerbExPo.getUiElCode())){
                            mapRes.put(etcmHerbExPo.getUiElCode(), etcmHerbExPo.getHerbExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }

        return resultList;
    }

    @Override
    public List<Map<String, String>> downloadIngredient(String content, String langCode, String uiTypeCode, String sortType) {
        QueryWrapper<EtcmHerbExPo> wrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like( "t1.ingr_zh_name", content)
                    .or().like( "t1.ingr_zh_name_py", content)
                    .or().like( "t1.ingr_zh_name_wb",content)
                    .or().like( "t1.ingr_zh_name_abb", content)
                    .or().like( "t1.ingr_en_name", content)
                    .or().like( "t1.ingr_en_name_abb", content)
                    .or().like( "t1.ingr_latin_name", content)
                    .or().like( "t1.ingr_latin_name_abb", content)
                    .or().like( "t1.ingr_name_alias", content)
            );
        }

        wrapper.eq("t1.status", CommonConsts.COMMON_YES);

        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t2.ingr_id");
        }else {
            wrapper.orderByDesc("t2.ingr_id");
        }
        wrapper.eq("t2.ui_type_code",uiTypeCode);
        wrapper.eq("t2.language_code",langCode);

        wrapper.groupBy("t2.ingr_id");
        List<EtcmIngrExPo> page = etcmIngrExMapper.downloadIngredient(wrapper);


        // List<Map<String,String>> resList = new ArrayList<>();
        Map<String,List<EtcmIngrExPo>> disMap = new LinkedHashMap<>(16);
        for (EtcmIngrExPo record : page) {
            List<EtcmIngrExPo> disList = new ArrayList<>();

            String[] uiElCodeList = record.getUiElCode().split("\\|\\|");
            String[] herbExConList = record.getIngrExCon().split("\\|\\|");
            for (int i = 0; i < uiElCodeList.length; i++) {
                EtcmIngrExPo etcmHerbExPo = new EtcmIngrExPo();

                for (int j = 0; j < herbExConList.length; j++) {
                    if (i == j){
                        etcmHerbExPo.setUiElCode(uiElCodeList[i]);
                        etcmHerbExPo.setIngrExCon(herbExConList[j]);

                    }
                }
                disList.add(etcmHerbExPo);
            }

            disMap.put(record.getIngrId(),disList);
        }


        List<EtcmUiElPo> etcmUiElPos = etcmPxExMapper.getUIElName(uiTypeCode,langCode);
        etcmUiElPos = etcmUiElPos.stream().filter(s -> s.getUiElSort() < 7).sorted(Comparator.comparing(EtcmUiElPo::getUiElSort)).collect(Collectors.toList());
        List<Map<String, String>> resultList = new ArrayList<>();

        for (String key : disMap.keySet()) {
            Map<String,String> mapRes=new HashMap<>(16);
            List<EtcmIngrExPo> values = disMap.get(key);
            List<String> collect = values.stream().map(EtcmIngrExPo::getUiElCode).collect(Collectors.toList());
            for (EtcmUiElPo etcmUiElPo : etcmUiElPos) {
                if (collect.contains(etcmUiElPo.getUiElCode())){
                    for (EtcmIngrExPo etcmHerbExPo : values) {
                        if (etcmUiElPo.getUiElCode().equals(etcmHerbExPo.getUiElCode())){
                            mapRes.put(etcmHerbExPo.getUiElCode(), etcmHerbExPo.getIngrExCon());
                        }
                    }
                }else {
                    mapRes.put(etcmUiElPo.getUiElCode(), "");
                }

            }

            resultList.add(mapRes);
        }

        return resultList;
    }

    @Override
    public List<Map<String, String>> getDownloadExperimentalRecords(String content, String langCode, String uiTypeCode, String ingrId, String sortType) {
        QueryWrapper<EtcmExperimentalRecordsPo> wrapper = new QueryWrapper<>();
        wrapper.eq("t1.ingr_id",ingrId);

        if(com.newviews.tcmip.common.utils.StringUtils.isNotBlank(content)){
            wrapper.and(w->w.like("t2.er_zh_name", content)
                    .or().like("t2.er_zh_name_py", content)
                    .or().like("t2.er_zh_name_wb", content)
                    .or().like("t2.er_zh_name_abb", content)
                    .or().like("t2.er_en_name", content)
                    .or().like("t2.er_en_name_abb", content)
                    .or().like("t2.er_latin_name", content)
                    .or().like("t2.er_latin_name_abb", content)
                    .or().like("t2.er_name_alias", content));
        }
        if(sortType.equalsIgnoreCase(CommonConsts.SORT_TYPE_ASC)){
            wrapper.orderByAsc("t1.er_id");
        }else {
            wrapper.orderByDesc("t1.er_id");
        }
        List<EtcmExperimentalRecordsIngrPo> pageEr = etcmIngrExMapper.getListErDownload( wrapper);
        List<Map<String,String>> resultList=new ArrayList<>();

        List<EtcmUiElPo> uiElName = etcmPxExMapper.getUIElName(uiTypeCode, langCode);
        for (EtcmExperimentalRecordsIngrPo record : pageEr) {
            Map<String, String> map = getStringStringMap(langCode, record, uiElName);
            resultList.add(map);
        }
        return resultList;
    }
    private static Map<String, String> getStringStringMap(String langCode, EtcmExperimentalRecordsIngrPo recordsIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getErZhName());
                    }
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getPubchemCid());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularFormula());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getMolecularWeight());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(), recordsIngrPo.getConcentration());
                    break;
                case 8:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getCelllines());
                    break;
                case 9:
                    map.put(etcmUiElPo.getUiElCode(),recordsIngrPo.getOrangism());
                default:
            }

        }
        return map;
    }

    private static Map<String, String> getStringStringMap(String langCode, EtcmIngrTargetPo etcmIngrTargetPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTargetId());
                    break;
                case 3:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getSymbolIdHum());
                    break;

                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getTypeName());
                    break;
                case 6:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrTargetPo.getEntrezIdHum());
                    break;
                case 7:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrTargetPo.getUniprotIdHum());
                default:
            }

        }
        return map;
    }
    private static Map<String, String> getStringStringMap(String langCode, EtcmIngrDiseasePo etcmIngrDiseasePo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseId() + "-" + etcmIngrDiseasePo.getIngrId());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getDiseaseZhName());
                    }
                    break;

                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrZhName());
                    }
                    break;
                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrDiseasePo.getIngrDiseaseDistance());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrDiseasePo.getPValue());
                default:
            }

        }
        return map;
    }


    private static Map<String, String> getStringStringMap(String langCode, EtcmIngrIngrPo etcmIngrIngrPo, List<EtcmUiElPo> uiElNameList) {
        Map<String,String> map = new HashMap<>(16);
        for (EtcmUiElPo etcmUiElPo : uiElNameList) {
            switch (etcmUiElPo.getUiElSort()){
                case 1:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrCode() + "-" + etcmIngrIngrPo.getTargetIngrCode());
                    break;
                case 2:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrZhName());
                    }
                    break;

                case 3:
                    if (CommonConsts.LANG_CODE_ENG.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getTargetIngrEnName());
                    }
                    if (CommonConsts.LANG_CODE_CHN.equals(langCode)){
                        map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getTargetIngrZhName());
                    }
                    break;
                case 4:
                    map.put(etcmUiElPo.getUiElCode(), etcmIngrIngrPo.getIngrIngrDistance());
                    break;
                case 5:
                    map.put(etcmUiElPo.getUiElCode(),etcmIngrIngrPo.getPValue());
                default:
            }

        }
        return map;
    }
}
